package com.design.behavioral;

/**
 * 命令模式：将一个请求封装为一个对象，从而使你可用不同的请求对客户进行参数化；对请求排队或记录请求日志，以及支持可撤消的操作。
 */
public class CommandDemo {
    public static void main(String[] args) {
        Receiver receiver = new Receiver();
        TurnOffThread turnOffThread = new TurnOffThread(receiver);
        Thread thread = new Thread(turnOffThread);
        Thread thread1 = new Thread(turnOffThread);

        thread.start();
        thread1.start();
    }
}

class TurnOffThread implements Runnable{
    private Receiver receiver;

    public TurnOffThread(Receiver receiver){
        this.receiver = receiver;
    }

    @Override
    public void run() {
        receiver.turnOff();
    }
}

class Receiver{
    public void turnOff(){
        System.out.println(Thread.currentThread().getName() + " turnOff method");
    }
}